< previous page page_665 next page >

Page 665
z0685-01.gif
Figure 19.2
A vector plus a vector equals a vector.
Conversely, if C is a vector in the plane containing A and B, there is some i and j for which C = i * A + j * B. This gives you a way to generate points on a plane. Calculate vectors C for different values of i and j and add the resulting vectors to a point on the plane. The RayCheckerboard class described in Chapter 17, Ray Tracing, uses this technique.
Vector Length
The length of a vector V = <vx, vy, vz> is written |V| and is given by Sqr(vx * vx + vy * vy + vz * vz).
A vector V is normalized if |V| = 1. When you normalize a vector, you make its length 1 while keeping it pointed in its original direction. To normalize a vector, divide each of its components by the vector's length: <vx/|V|, vy/|V|, vz/|V|>.
Normalized vectors are particularly useful with dot products and cross products. The lengths of the vectors play a role in these calculations, and if the vectors have length 1, the calculations are simpler.
Dot Product
The dot product of two vectors A and B is written A B and has value |A| * |B| * Cos(q) where q is the angle between the two vectors. Mathematically, you can calculate the dot product by multiplying the corresponding components of two vectors and adding the results:
e10a6a0a59f035e870d90cca05b85fce.gif
A  B = ax * bx + ay * by + az * bz
This gives you method for calculating the cosine of the angle between two vectors:
e10a6a0a59f035e870d90cca05b85fce.gif
Cos(q) = (A  B)/(|A| * |B|)
If the vectors A and B are normalized, this simplifies to:
e10a6a0a59f035e870d90cca05b85fce.gif
Cos (q) = A · B

 
< previous page page_665 next page >